<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorate="body/main">
<head>
    <meta charset="UTF-8">
    <title>主页</title>
</head>
<body class="nav-md footer_fixed">
<div class="right_col" role="main" layout:fragment="content">
    <div class="">

        <div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>
                            角色信息管理维护 <i class="fa fa-user"></i><small th:text="${session.user.usrName}"></small>
                        </h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <form method="post" action="/user/list" th:action="@{/role/list}">
                            <input type="hidden" name="pageIndex" value="1" />
                            <ul>
                                <li>
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">角色名称</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input name="roleName" type="text" class="form-control col-md-7 col-xs-12" th:value="${roleName}">
                                        </div>
                                    </div>
                                </li>
                                <li><button type="submit" class="btn btn-primary"> 查 &nbsp;&nbsp;&nbsp;&nbsp;询 </button></li>
                            </ul>
                        </form>
                    </div>
                </div>
            </div>
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_content">
                        <p class="text-muted font-13 m-b-30"></p>
                        <div id="datatable-responsive_wrapper"
                             class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                            <div class="row">
                                <div class="col-sm-12">                                     <!--shiro:hasPermission="用户添加"-->
                                    <a href="/user/add" th:href="@{/role/add}" class="btn btn-success btn-sm" >新增角色信息</a>
                                    <table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap dataTable no-footer dtr-inline collapsed"
                                           cellspacing="0" width="100%" role="grid" aria-describedby="datatable-responsive_info" style="width: 100%;">
                                        <thead>
                                        <tr role="row">
                                            <th class="sorting_asc" tabindex="0"
                                                aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                                aria-label="First name: activate to sort column descending"
                                                aria-sort="ascending">角色编号</th>
                                            <th class="sorting" tabindex="0"
                                                aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                                aria-label="Last name: activate to sort column ascending">
                                                角色名称</th>
                                            <th class="sorting" tabindex="0"
                                                aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                                aria-label="Last name: activate to sort column ascending">
                                                角色描述</th>
                                            <th class="sorting" tabindex="0"
                                                aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                                aria-label="Last name: activate to sort column ascending">
                                                角色状态</th>
                                            <th class="sorting" tabindex="0"
                                                aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                                aria-label="Last name: activate to sort column ascending">
                                                操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr role="row" class="odd" th:each="role,status : ${rolePage.getContent()}">
                                            <td tabindex="0" class="sorting_1" th:text="${role.roleId}"></td>
                                            <td th:text="${role.roleName}"></td>
                                            <td th:text="${role.roleDesc}"></td>
                                            <td th:if="${role.roleFlag eq 1}">启用</td>
                                            <td th:if="${role.roleFlag == null}">禁用</td>
                                            <td>
                                                <div class="btn-group">
                                                    <button type="button" class="btn btn-danger">点击操作</button>
                                                    <button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                                        <span class="caret"></span>
                                                        <span class="sr-only">Toggle Dropdown</span>
                                                    </button>
                                                    <ul class="dropdown-menu" role="menu">
                                                        <li>
                                                            <a class="saleSwichOpen" saleSwitch="open" data-toggle="tooltip" data-placement="top" title=""
                                                            th:href="@{/role/edit(roleId=${role.roleId})}">修改</a>
                                                        </li>
                                                        <li>
                                                            <a class="addVersion" data-toggle="tooltip" data-placement="top" title=""
                                                               href="#"th:onclick="'javascript:doDel(this,'+${role.roleId}+');'">删除</a>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-5">
                                    <div class="dataTables_info" id="datatable-responsive_info"
                                         role="status" aria-live="polite">共<span th:text="${totalElements}"></span>条记录
                                        <span th:text="${number}"></span>/<span th:text="${totalPages}"></span>页</div>
                                </div>

                                <div class="col-sm-7">
                                    <div class="dataTables_paginate paging_simple_numbers"
                                         id="datatable-responsive_paginate">
                                        <ul class="pagination">
                                            <li class="paginate_button previous" th:if="${number gt 1}"><a
                                                    href="javascript:page_nav(document.forms[0],1);"
                                                    aria-controls="datatable-responsive" data-dt-idx="0"
                                                    tabindex="0">首页</a>
                                            </li>
                                            <li class="paginate_button " th:if="${number gt 1}"><a
                                                    href="#"th:onclick="'javascript:page_nav(document.forms[0],'+${number - 1}+');'"
                                                    aria-controls="datatable-responsive" data-dt-idx="1"
                                                    tabindex="0">上一页</a>
                                            </li>
                                            <li class="paginate_button " th:if="${number lt totalPages}"><a
                                                    href="#"th:onclick="'javascript:page_nav(document.forms[0],'+${number + 1}+');'"
                                                    aria-controls="datatable-responsive" data-dt-idx="1"
                                                    tabindex="0">下一页</a>
                                            </li>
                                            <li class="paginate_button next" th:if="${number lt totalPages}"><a
                                                    href="#"th:onclick="'javascript:page_nav(document.forms[0],'+${totalPages}+');'";
                                                    aria-controls="datatable-responsive" data-dt-idx="7"
                                                    tabindex="0">最后一页</a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script layout:fragment="js" th:inline="javascript">
    function  doDel(obj,roleId){
        if(confirm("你确定要删除改用户信息吗？")){
            $.ajax({
                type:"DELETE",
                url:"/crm/role/del",
                data:"roleId="+roleId,
                dataType:"json",
                success:function (data){
                    if(data.delResult == true){
                        alert("删除成功！");
                        /*$(obj).parents("tr").remove();*/
                        location.reload();
                    }
                },
                error:function (data){
                    alert("对不起，删除失败！");
                }
            })
        }
    }

    /*$(document).ready(function (){
       $.ajax({
           type:"GET",
           url:"/crm/role/json",
           success:function (data){
                $("#roleId").html("");
                var roleId = [[${roleId}]]; //获取Model里面的roleId
                var options = "<option value='0'>--请选择--</option>";
                for(var i = 0; i < data.length; i++){
                    if(roleId != null && roleId != undefined && data[i].roleId == roleId){
                        options += "<option selected=\"selected\" value=\""+data[i].roleId+"\" >"+data[i].roleName+"</option>";
                    }else{
                        options += "<option value=\""+data[i].roleId+"\" >"+data[i].roleName+"</option>";
                    }
                }
                $("#roleId").html(options);
           },
           error:function (data){
               alert("对不起，获取数据失败！");
           }
       })
    });*/
</script>
</html>